package com.naire.modul.${packageName}.dao.impl;

import java.util.ArrayList;
import java.util.List;

import net.common.dao.GeneralDaoImpl;
import net.common.service.PageBean;
import net.common.util.BeanUtils;
import com.naire.modul.${packageName}.dao.${className}Dao;
import com.naire.modul.${packageName}.pojo.${className};
import com.naire.modul.${packageName}.vo.${className}Vo;

public class ${className}DaoImpl extends GeneralDaoImpl implements ${className}Dao {

	@SuppressWarnings("unchecked")
	@Override
	public List<${className}Vo> search(PageBean pageBean) throws Exception {
		StringBuilder hql = new StringBuilder("from ${className} where flag=0");
		List<${className}Vo> d = new ArrayList<${className}Vo>();
		List<${className}> l = hibernateHandler.query(hql, pageBean);
		for(${className} bean : l) {
			${className}Vo dv = new ${className}Vo();
			BeanUtils.copyProperties(bean, dv);
			d.add(dv);
		}
		return d;
	}

	@Override
	public void insert(${className}Vo bean) throws Exception {
		${className} pojo = new ${className}();
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.insert(pojo);
	}

	@Override
	public void update(${className}Vo bean) throws Exception {
		${className} pojo = (${className})hibernateHandler.find(${className}.class, bean.get${p_column}());
		BeanUtils.copyProperties(bean, pojo);
		hibernateHandler.update(pojo);
	}

	@Override
	public void updateFlag(${className}Vo bean) throws Exception {
		update(bean);
	}

	@Override
	public ${className}Vo find(Integer id) throws Exception {
		${className} pojo = (${className})hibernateHandler.find(${className}.class, id);
		${className}Vo bean = new ${className}Vo();
		BeanUtils.copyProperties(pojo, bean);
		return bean;
	}
}
